import java.util.Arrays;
import java.util.Stack;

public class L1047 {
    public static void main(String[] args) {
        String abbaca = new Solution().removeDuplicates("abbaca");
        System.out.println(abbaca);
    }


    static class Solution {
        public String removeDuplicates(String s) {
            Stack<Character> characters = new Stack<>();
            char[] chars = s.toCharArray();
            for (char c : chars) {
                if (!characters.isEmpty() && c == characters.peek()) {
                    characters.pop();
                } else {
                    characters.push(c);
                }
            }
            if (characters.isEmpty()) {
                return "";
            }
            Stack<Character> stack = new Stack<>();
            while (!characters.isEmpty()) {
                stack.push(characters.pop());
            }
            int size = stack.size();
            char[] result = new char[size  ];
            for (int i = 0; i < size; i++) {
                result[i] = stack.pop();
            }
            return new String(result);

        }
    }
}
